package nju.se.alibaba.algorithm;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

import nju.se.alibaba.model.Tmall;

public class Algorithm {
	public HashMap<Integer, HashSet<Integer>> getResults(){
		return null;
	}
	public void writeToFile(HashMap<Integer, HashSet<Integer>> result, String fileName){
		try {
			FileWriter outFile = new FileWriter(new File(fileName));
			Set<Integer>keys = result.keySet();
			for(Integer key:keys){
				outFile.write(key+"\t");
				HashSet<Integer>brands=result.get(key);
				String tmp = "";
				for (Integer brand:brands) {
					tmp+=brand+",";
				}
				tmp = tmp.substring(0, tmp.length()-1);
				tmp+="\n";
				outFile.write(tmp);
				
			}
			outFile.flush();
			outFile.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void writeToConsole(HashMap<Integer, HashSet<Integer>> result){
		Set<Integer>keys = result.keySet();
		for(Integer key:keys){
			System.out.print(key+"\t");
			HashSet<Integer>brands=result.get(key);
			String tmp = "";
			for (Integer brand:brands) {
				tmp+=brand+",";
			}
			tmp = tmp.substring(0, tmp.length()-1);
			tmp+="\n";
			System.out.print(tmp);
		}
	}
}
